from PySide2.QtWidgets import QWidget
from forms.uipy.UI_ele_situation import Ui_Ele_Situation
from tools.File_Select_Tools import File_Select_Tools
from server.Ele_SituationService import Ele_SituationService

# 电子记账汇总界面实现类
class Ele_SituationImpl(QWidget, Ui_Ele_Situation):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.bindEvent()

    def bindEvent(self):
        self.pre_month_btn.clicked.connect(
            lambda: self.pre_month_path.setText(File_Select_Tools.select_one_file(title="前月记账概览文件选择")[0]))
        self.now_month_btn.clicked.connect(
            lambda: self.now_month_path.setText(File_Select_Tools.select_one_file(title="当月记账概览文件选择")[0]))
        self.now_review_btn.clicked.connect(
            lambda: self.now_review_path.setText(File_Select_Tools.select_one_file(title="当月记账复核文件选择")[0]))
        self.community_btn.clicked.connect(
            lambda: self.community_path.setText(File_Select_Tools.select_one_file(title="小区样本文件选择")[0]))
        self.out_btn.clicked.connect(
            lambda: self.out_path.setText(str(File_Select_Tools.select_dir(title="输出位置选择"))))
        # TODO 运行按钮点击但是路径为空的情况
        self.run_btn.clicked.connect(lambda: Ele_SituationService(self.pre_month_path.text(),
                                                                  self.now_month_path.text(),
                                                                  self.now_review_path.text(),
                                                                  self.community_path.text(),
                                                                  self.out_path.text(),
                                                                  self.summary_review.isChecked()
                                                                  ).initData())

